// State.h

#pragma once
#include "Line.h"
#include "Station.h"
#include <list>
#include <functional>

class StateTransition;

using namespace std;

class State
{
public:
	Line*					m_Line;
	Station*				m_Station;
	int						m_CostByParent;
	int						m_CostByChild;
	State*					m_Parent;
	State*					m_Child;
	list<State*>			m_Successors;
	list<StateTransition*>	m_SuccessorTransitions;
	bool					m_bClosedByParent;
	bool					m_bClosedByChild;
	bool					m_bOpenedByParent;
	bool					m_bOpenedByChild;

	State();
	State(Line* Line, Station* Station);

	void	Reset();
	int		GetTransitionCost(State* NextState, bool bIsFirstStation=false);

	bool	IsClosed(bool bBackward=false);
	bool	IsOpened(bool bBackward=false);
	int		GetCost(bool bBackward=false);
	void	SetClosed(bool bClosed, bool bBackward=false);
	void	SetOpened(bool bClosed, bool bBackward=false);
	void	SetCost(int Cost, bool bBackward=false);
	void	SetParent(State* Parent, bool bBackward=false);
};

inline bool operator == (const State& a, const State& b){return a.m_Line == b.m_Line && a.m_Station == b.m_Station;}
inline bool operator != (const State& a, const State& b){return a.m_Line != b.m_Line || a.m_Station != b.m_Station;}

struct StateForwardPriorityComparator
{
	bool operator()(const State* a, const State* b) const
	{
		return a->m_CostByParent > b->m_CostByParent;
	}
};

struct StateBackwardPriorityComparator
{
    bool operator()(const State* a, const State* b) const
	{
		return a->m_CostByChild > b->m_CostByChild;
	}
};